exports.callback = done => {
    console.log("callback");
    done()
}

exports.callback_error = done => {
    console.log("callback_error");
    done(new Error("callback_error"))
}

exports.promise = () => {
    console.log("promise")
    return Promise.resolve()
}

exports.promise_error = () => {
    console.log("promise_error")
    return Promise.reject("promise_error")
}

const timer = time => new Promise(resolve => setTimeout(resolve, time))
exports.async = async () => {
    await timer(1000);
    console.log("async")
}

const fs = require("fs")
exports.stream = done => {
    const readStream = fs.createReadStream("package.json");
    const writeStream = fs.createWriteStream("lx.txt")
    readStream.pipe(writeStream)
    // return readStream
    // 返回readStream的本质是对它的end方法进行监听
    readStream.on("end", () => {
        done()
    })
}